<?php 
	$product = empty($product) ? array() : $product;
?>

<p><?= $this->Html->link("&laquo; Nazad na listu proizvoda", "/proizvodi", array('escape'=>false)) ?></p>

<?= $this->Form->create("Product", array("url"=>"/proizvodi/sacuvaj", "class"=>"entity-form")) ?>
	
	<?= $this->Form->hidden("id", array("value"=>@$product['Product']['id'])) ?>
	
	<?= $this->Form->label('product_type_id', 'Kategorija:') ?>
	<div class="radios">
		<?= $this->Form->radio('product_type_id', $product_types, array(
			'value' => @$product['Product']['product_type_id'],
			'legend' => false
		)) ?>
	</div>
	
	<?= $this->Form->label('name', 'Naziv:') ?>
	<?= $this->Form->text('name', array('value'=>@$product['Product']['name'])) ?>
	
	<?= $this->Form->label('lifetime', 'Rok trajanja:') ?>
	<?= $this->Form->text('lifetime', array('value'=>@$product['Product']['lifetime'], 'class'=>'small')) ?>
	<span class="value" style="margin:7px 0">dana</span>
	
	<?php
		$productCodes = Set::combine(@$product['ProductClients'], '{n}.client_id', '{n}');
	?>
	<fieldset>
		<legend>Šifre proizvoda po klijentu:</legend>
		<? $k=0; ?>
		<? foreach($clients as $id=>$name): ?>
			<?= $this->Form->hidden("ProductClients.{$k}.id", array("value" => @$productCodes[$id]['id'])) ?>
			<?= $this->Form->hidden("ProductClients.{$k}.client_id", array("value" => $id)) ?>
			
			<?= $this->Form->label("ProductClients.{$k}.code", $name . ":", array('class'=>'inline')) ?>
			<?= $this->Form->text("ProductClients.{$k}.code", array('class'=>'medium', 'value'=>@$productCodes[$id]['code'])) ?>
			<? $k++ ?>
		<? endforeach; ?>
	</fieldset>
	
	<?= $this->Form->label('ProductPrice.-1.price', 'Nova cena:') ?>
	<?= $this->Form->text('ProductPrice.-1.price', array('class'=>'medium', 'value'=>@$product['ProductPrice'][-1]['value'])) ?>
	<?= $this->Form->label('ProductPrice.-1.effective_date', 'Od:', array('class'=>'auto inline')) ?>
	<?= $this->Form->text('ProductPrice.-1.effective_date', array('class'=>'datepicker', 'value'=> empty($data['ProductPrice'][-1]['effective_date']) ? date('Y-m-d') : $data['ProductPrice'][-1]['effective_date'])) ?>
	
	<? if(!empty($product['ProductPrice'])): ?>
		<? unset($product['ProductPrice'][-1]) ?>
	<? endif; ?>
	<br clear="all">
	<div class="label">Cene:</div>
	<div class="value list-values">
		<? if(!empty($product['ProductPrice'])): ?>
		<? foreach($product['ProductPrice'] as $k=>$price): ?>
		<div style="opacity:<?= $k==0 ? 1 : 0.4 ?>">
			<?= $this->Form->hidden("ProductPrice.{$k}.id", array("value"=>$price['id'])) ?>
			<?= $this->Form->hidden("ProductPrice.{$k}.price", array("value"=>$price['price'])) ?>
			<?= $this->Form->hidden("ProductPrice.{$k}.effective_date", array("value"=>$price['effective_date'])) ?>
			<strong><?= number_format($price['price'], 2, ",", ".") ?></strong> (<?= local_date($price['effective_date']) ?>)
			<a class="btn delete" href="javascript:void(0)" onclick="if(confirm('Da li želite da obrišete cenu?')){$(this).parent().remove()}">x</a>
		</div>
		<? endforeach; ?>
		<? endif; ?>
	</div>
	
	<?= $this->Form->submit("Sačuvaj", array('div'=>false))?>
<?= $this->Form->end() ?>
